package org.example.datascreen.service.Impl;

import org.example.datascreen.eneity.User;
import org.example.datascreen.eneity.VO.RegisterVO;
import org.example.datascreen.repository.UserRepository;
import org.example.datascreen.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserRepository userRepository;

    @Override
    public String register(RegisterVO registerVO) {
        if (!registerVO.getPassword().equals(registerVO.getRepassword()))
            return "两次密码不一致";
        User user = userRepository.findByUsername(registerVO.getUsername());
        if (user == null) { //用户名不存在
            user = new User();
            user.setUsername(registerVO.getUsername());
            user.setPassword(registerVO.getPassword());
            user.setCreatedTime(new Date());
            userRepository.save(user);
            return "1";
        } else {
            return "用户名已存在";
        }
    }
}
